<?php
//session_start();
if(isset($_GET['fileId'])) 
{
// if id is set then get the file with the id from database

include '../../config.php';
include './dbOpenConn.php';
$fileId    = $_GET['fileId'];
$query = "SELECT filename, type, size, data " .
         "FROM files WHERE id = '$fileId'";

$result = mysql_query($query) or die('Error, query failed');
list($filename, $type, $size, $data) = mysql_fetch_array($result);

header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$filename");
echo $data;

mysql_close();
exit;
}

?>